package com.paas.form.controller;


import com.paas.common.model.RestResponse;
import com.paas.common.util.StringUtil;
import com.paas.common.web.controller.BaseController;
import com.paas.form.service.IFormViewPubService;
import com.paas.form.service.IFormViewService;
import com.paas.form.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

@RestController
@RequestMapping(value = "/form/formViewFinal")
@Api(description = "视图模块", tags = "")
public class FormViewFinalController extends BaseController {

    @Autowired
    public IFormViewService formViewService;

    @Autowired
    public IFormViewPubService formViewPubService;


    @RequestMapping(value = "/getViewFinalizeById",method = RequestMethod.GET)
    @ApiOperation(value = "根据id查询定版信息", notes = "根据id查询定版信息")
    public ViewFinalizeVo getViewFinalizeById(String viewId) throws ParseException {
        String viewFinalVesionId = viewId;
        ViewFinalizeVo viewFinalizeVo = new ViewFinalizeVo();
        if (StringUtil.isNotEmpty(viewFinalVesionId)){
            viewFinalizeVo =  formViewService.getViewFinalizeById(viewFinalVesionId);
        }
        return viewFinalizeVo;
    }

    @RequestMapping(value = "/approvalViewChange",method = RequestMethod.POST)
    @ApiOperation(value = "同意定版视图", notes = "同意定版视图")
    public RestResponse approvalViewChange(String bussinessKey) throws ParseException {
        if (StringUtil.isNotEmpty(bussinessKey)){

            return formViewService.approvalViewChange(bussinessKey);
        }
        return RestResponse.error();

    }


    @RequestMapping(value = "/opposeViewFinalize",method = RequestMethod.POST)
    @ApiOperation(value = "反对定版视图", notes = "反对定版视图")
    public RestResponse opposeViewFinalize(String bussinessKey) throws ParseException {
        if (StringUtil.isNotEmpty(bussinessKey)){
            return  formViewService.opposeViewFinalize(bussinessKey);
        }
        return RestResponse.error();
    }


}